<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="领用计划号" prop="lyDanhao">
        <el-input
          v-model="queryParams.lyDanhao"
          placeholder="请输入领用计划号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售订单编号" prop="orderDanhao">
        <el-input
          v-model="queryParams.orderDanhao"
          placeholder="请输入销售订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料类型编码" prop="classId">
        <el-input
          v-model="queryParams.classId"
          placeholder="请输入物料类型编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料类型" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="请输入物料类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编号" prop="itemId">
        <el-input
          v-model="queryParams.itemId"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
   <!--   <el-form-item label="物料子编号" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入物料子编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="规格型号" prop="spec">
        <el-input
          v-model="queryParams.spec"
          placeholder="请输入规格型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="物料单位" prop="unit">
        <el-input
          v-model="queryParams.unit"
          placeholder="请输入物料单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
     <!-- <el-form-item label="供应商编码" prop="supplyId">
        <el-input
          v-model="queryParams.supplyId"
          placeholder="请输入供应商编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商名称" prop="supplyName">
        <el-input
          v-model="queryParams.supplyName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制造商编码" prop="makerCode">
        <el-input
          v-model="queryParams.makerCode"
          placeholder="请输入制造商编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制造商名称" prop="makerName">
        <el-input
          v-model="queryParams.makerName"
          placeholder="请输入制造商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="派工工位编码" prop="gwCode">
        <el-input
          v-model="queryParams.gwCode"
          placeholder="请输入派工工位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="派工工位名称" prop="gwName">
        <el-input
          v-model="queryParams.gwName"
          placeholder="请输入派工工位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="质量状态" prop="qualityState">
        <el-input
          v-model="queryParams.qualityState"
          placeholder="请输入质量状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用状态" prop="useState">
        <el-input
          v-model="queryParams.useState"
          placeholder="请输入使用状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="color">
        <el-input
          v-model="queryParams.color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="花纹" prop="figure">
        <el-input
          v-model="queryParams.figure"
          placeholder="请输入花纹"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质" prop="caizhi">
        <el-input
          v-model="queryParams.caizhi"
          placeholder="请输入材质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:planItemGet:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:planItemGet:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:planItemGet:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:planItemGet:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="planItemGetList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="领用计划号" width="130" show-overflow-tooltip align="center" prop="lyDanhao" />
      <el-table-column label="领用计划数量" width="110" align="center" prop="jhNum" />
      <el-table-column label="销售订单编号" width="130" show-overflow-tooltip align="center" prop="orderDanhao" />
      <el-table-column label="订单类型" align="center" prop="orderType" />
      <el-table-column label="出库类型" align="center" prop="chukuType" />
      <el-table-column label="物料类型编码" width="130" show-overflow-tooltip align="center" prop="classId" />
      <el-table-column label="物料类型" align="center" prop="className" />
      <el-table-column label="物料名称" width="130" show-overflow-tooltip align="center" prop="itemName" />
      <el-table-column label="物料编号" width="130" show-overflow-tooltip align="center" prop="itemId" />
<!--
      <el-table-column label="物料子编号" align="center" prop="itemCode" />
-->
      <el-table-column label="规格型号" width="130" show-overflow-tooltip align="center" prop="spec" />
      <el-table-column label="物料单位" align="center" prop="unit" />
      <el-table-column label="供应商编码" width="130" show-overflow-tooltip  align="center" prop="supplyId" />
      <el-table-column label="供应商名称" width="130" show-overflow-tooltip align="center" prop="supplyName" />
      <el-table-column label="制造商编码" width="130" show-overflow-tooltip align="center" prop="makerCode" />
      <el-table-column label="制造商名称" width="130" show-overflow-tooltip align="center" prop="makerName" />
      <el-table-column label="派工工位编码" width="130" show-overflow-tooltip align="center" prop="gwCode" />
      <el-table-column label="派工工位名称" width="130" show-overflow-tooltip align="center" prop="gwName" />
      <el-table-column label="质量状态" align="center" prop="qualityState" />
      <el-table-column label="使用状态" align="center" prop="useState" />
      <el-table-column label="颜色" align="center" prop="color" />
      <el-table-column label="花纹" align="center" prop="figure" />
      <el-table-column label="材质" align="center" prop="caizhi" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" fixed="right" width="180" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-checked"
            @click="handleScChuKu(scope.row)"
            v-hasPermi="['business:planItemGet:scChuKu']"
          >生成</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:planItemGet:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:planItemGet:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改物料领用计划对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="领用计划数量" prop="jhNum">
          <el-input v-model="form.jhNum" placeholder="请输入领用计划数量" />
        </el-form-item>
        <el-form-item label="销售订单编号" prop="orderDanhao">
          <el-input v-model="form.orderDanhao" placeholder="请输入销售订单编号" />
        </el-form-item>
        <el-form-item label="物料类型编码" prop="classId">
          <el-input v-model="form.classId" placeholder="请输入物料类型编码" />
        </el-form-item>
        <el-form-item label="物料类型" prop="className">
          <el-input v-model="form.className" placeholder="请输入物料类型" />
        </el-form-item>
        <el-form-item label="物料名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="物料编号" prop="itemId">
          <el-input v-model="form.itemId" placeholder="请输入物料编号" />
        </el-form-item>
        <el-form-item label="物料子编号" prop="itemCode">
          <el-input v-model="form.itemCode" placeholder="请输入物料子编号" />
        </el-form-item>
        <el-form-item label="规格型号" prop="spec">
          <el-input v-model="form.spec" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="物料单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入物料单位" />
        </el-form-item>
        <el-form-item label="供应商编码" prop="supplyId">
          <el-input v-model="form.supplyId" placeholder="请输入供应商编码" />
        </el-form-item>
        <el-form-item label="供应商名称" prop="supplyName">
          <el-input v-model="form.supplyName" placeholder="请输入供应商名称" />
        </el-form-item>
        <el-form-item label="制造商编码" prop="makerCode">
          <el-input v-model="form.makerCode" placeholder="请输入制造商编码" />
        </el-form-item>
        <el-form-item label="制造商名称" prop="makerName">
          <el-input v-model="form.makerName" placeholder="请输入制造商名称" />
        </el-form-item>
        <el-form-item label="派工工位编码" prop="gwCode">
          <el-input v-model="form.gwCode" placeholder="请输入派工工位编码" />
        </el-form-item>
        <el-form-item label="派工工位名称" prop="gwName">
          <el-input v-model="form.gwName" placeholder="请输入派工工位名称" />
        </el-form-item>
        <el-form-item label="质量状态" prop="qualityState">
          <el-input v-model="form.qualityState" placeholder="请输入质量状态" />
        </el-form-item>
        <el-form-item label="使用状态" prop="useState">
          <el-input v-model="form.useState" placeholder="请输入使用状态" />
        </el-form-item>
        <el-form-item label="颜色" prop="color">
          <el-input v-model="form.color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="花纹" prop="figure">
          <el-input v-model="form.figure" placeholder="请输入花纹" />
        </el-form-item>
        <el-form-item label="材质" prop="caizhi">
          <el-input v-model="form.caizhi" placeholder="请输入材质" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPlanItemGet, getPlanItemGet, delPlanItemGet, addPlanItemGet, updatePlanItemGet,addScChuKu} from "@/api/business/planItemGet";

export default {
  name: "PlanItemGet",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料领用计划表格数据
      planItemGetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lyDanhao: null,
        orderDanhao: null,
        orderType: null,
        chukuType: null,
        classId: null,
        className: null,
        itemName: null,
        itemId: null,
        itemCode: null,
        spec: null,
        unit: null,
        supplyId: null,
        supplyName: null,
        makerCode: null,
        makerName: null,
        gwCode: null,
        gwName: null,
        qualityState: null,
        useState: null,
        color: null,
        figure: null,
        caizhi: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询物料领用计划列表 */
    getList() {
      this.loading = true;
      listPlanItemGet(this.queryParams).then(response => {
        this.planItemGetList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryName: null,
        factoryCode: null,
        lyDanhao: null,
        jhNum: null,
        orderDanhao: null,
        orderType: null,
        chukuType: null,
        classId: null,
        className: null,
        itemName: null,
        itemId: null,
        itemCode: null,
        spec: null,
        unit: null,
        supplyId: null,
        supplyName: null,
        makerCode: null,
        makerName: null,
        gwCode: null,
        gwName: null,
        qualityState: null,
        useState: null,
        color: null,
        figure: null,
        caizhi: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加物料领用计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPlanItemGet(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改物料领用计划";
      });
    },
    handleScChuKu(row){
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认生成出库单"' + row.lyDanhao+'?').then(function() {
        return addScChuKu(ids);
      }).then(() => {
        this.getList();
        this.$modal.alertSuccess("生成出库单成功");
      }).catch(() => {});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePlanItemGet(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlanItemGet(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除物料领用计划编号为"' + ids + '"的数据项？').then(function() {
        return delPlanItemGet(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/planItemGet/export', {
        ...this.queryParams
      }, `planItemGet_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
